<?php
Yii::import('common.models.cms.*');
class ContentPage extends BlockComponent{
    public $id = 'contentpage';
    public $postId;

    public function run(){
        parent::run();

        //load the post model
        $model = Post::model()->findByPk($this->postId);
        $this->render($this->outputView, array(
            'model' => $model
        ));
    }

    public function params() {
        return array(
            'postId' => 'Post Id'
        );
    }

    public function validate() {
        if($this->postId != NULL){
            //check valid page
            $count = db()->createCommand()
                    ->select('COUNT(*)')
                    ->from('{{posts}}')
                    ->where('post_id = :id', array(
                        ':id' => $this->postId
                    ))
                    ->queryScalar();

            if(!$count){
                //set errors
                $this->errors['postId'] = 'Page was not exists';
            }

            return true;
        }

        return false;
    }
}